package com.courier.mapper;

import com.courier.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {
    @Select("SELECT * FROM user_info WHERE id = #{id}")
    User findById(Long id);
    
    @Select("SELECT * FROM user_info WHERE username = #{username}")
    User findByUsername(String username);
    
    @Insert("INSERT INTO user_info(username, password, real_name, phone, role, status, create_time, update_time) " +
            "VALUES(#{username}, #{password}, #{realName}, #{phone}, #{role}, #{status}, #{createTime}, #{updateTime})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    boolean insert(User user);
    
    @Update("UPDATE user_info SET username = #{username}, password = #{password}, real_name = #{realName}, " +
            "phone = #{phone}, role = #{role}, status = #{status}, update_time = #{updateTime} WHERE id = #{id}")
    boolean update(User user);
    
    @Delete("DELETE FROM user_info WHERE id = #{id}")
    boolean deleteById(Long id);
    
    @Update("UPDATE user_info SET status = #{status}, update_time = now() WHERE id = #{id}")
    boolean updateStatus(@Param("id") Long id, @Param("status") Integer status);
    
    @Select("SELECT * FROM user_info")
    List<User> list();
}